﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace kongjian31
{
    [Designer(typeof(/*TongJi_EMS._TJ_Basic.TJ_BasicControlDesigner*/LineDesigner))]
    public partial class hengjiexian10kv : TongJi_EMS._TJ_Basic.TJ_BasicControl
    {
        private Color _lineColor = Color.Red;
        [CategoryAttribute("Data")]
        [Description("Set the Color of the line")]
        public Color LineColor
        {
            get { return _lineColor; }
            set
            {
                _lineColor = value;
                IComponentChangeService ccs = (IComponentChangeService)this.BasicControlDesigner.GetService_Open(typeof(IComponentChangeService));
                if (ccs != null)
                {
                    PropertyDescriptor lineColorProp = TypeDescriptor.GetProperties(this)["LineColor"];
                    ccs.OnComponentChanged(this, lineColorProp, null, null);
                    ccs.OnComponentChanging(this, lineColorProp);
                }
                this.Refresh();
            }
        }

        private int _lineWidth = 1;
        [CategoryAttribute("Data")]
        [Description("Set the Width of the line")]
        public int LineWidth
        {
            get { return _lineWidth; }
            set
            {
                _lineWidth = value;
                if (_lineWidth > 2)
                {
                    this.Height = _lineWidth;
                }
                this.Refresh();
            }
        }

        public hengjiexian10kv()
        {
            InitializeComponent();
        }

        private void jiexian10kv_Load(object sender, EventArgs e)
        {
            jiexian10kv_Resize(sender, e);


        }

        private void jiexian10kv_Paint(object sender, PaintEventArgs e)
        {
            Pen a = new Pen(CtrColor, _lineWidth);
            e.Graphics.DrawLine(a, 0, y, x * 2f, y);

        }

        private void jiexian10kv_Resize(object sender, EventArgs e)
        {
            this.x = this.Width / 2;
            this.y = this.Height / 2;
            //this.Refresh();
        }
    }

    internal class LineDesigner : TongJi_EMS._TJ_Basic.TJ_BasicControlDesigner
    {
        //public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        //{
        //    get
        //    {
        //        DesignerVerbCollection maindvc = base.Verbs;
        //        //DesignerVerbCollection subdvc = new DesignerVerbCollection(new DesignerVerb[]{new DesignerVerb("Red",new EventHandler(RedLineColor)),
        //        //    new DesignerVerb("Yellow",new EventHandler (YellowLineColor)),
        //        //    new DesignerVerb("Turquoise",new EventHandler(TurquoiseLineColor))});
        //        //maindvc.AddRange(subdvc);
        //        maindvc.Insert(0, new DesignerVerb("Turquoise", new EventHandler(TurquoiseLineColor)));
        //        maindvc.Insert(0, new DesignerVerb("Yellow", new EventHandler(YellowLineColor)));
        //        maindvc.Insert(0, new DesignerVerb("Red", new EventHandler(RedLineColor)));
        //        return maindvc;
        //    }
        //}

        public override SelectionRules SelectionRules
        {
            get
            {
                SelectionRules rules = base.SelectionRules;
                if (!TJ_BControl.Editable)
                    rules &= ~(SelectionRules.Moveable | SelectionRules.AllSizeable);
                else
                {

                    if (HengJieXian != null)
                    {
                        rules &= ~(SelectionRules.TopSizeable | SelectionRules.BottomSizeable);
                    }
                    else if (ShuJieXian != null)
                    {
                        rules &= ~(SelectionRules.LeftSizeable | SelectionRules.RightSizeable);
                    }
                }
                return rules;
            }
        }

        public hengjiexian10kv HengJieXian
        {
            get
            {
                return base.TJ_BControl as hengjiexian10kv;
            }
        }

        public kongjian32.shujiexian10kv ShuJieXian
        {
            get
            {
                return base.TJ_BControl as kongjian32.shujiexian10kv;
            }
        }

        private Color _lineColor
        {
            get
            {
                return HengJieXian.LineColor;
            }
            set
            {
                HengJieXian.LineColor = value;
                //IComponentChangeService ccs = (IComponentChangeService)GetService_Open(typeof(IComponentChangeService));
                //if (ccs != null)
                //{
                //    PropertyDescriptor lineColorProp = TypeDescriptor.GetProperties(typeof(kongjian32.shujiexian10kv))["LineColor"];
                //    ccs.OnComponentChanging(HengJieXian, lineColorProp);
                //    ccs.OnComponentChanged(HengJieXian, lineColorProp, null, null);
                //}
            }
        }

        private void RedLineColor(object sender, EventArgs e)
        {
            _lineColor = Color.Red;
        }

        private void YellowLineColor(object sender, EventArgs e)
        {
            _lineColor = Color.Yellow;
        }

        private void TurquoiseLineColor(object sender, EventArgs e)
        {
            _lineColor = Color.Turquoise;
        }
    }
}